<html>
<head><meta charset="utf-8"><title>generator resume args segfaults · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generator.20resume.20args.20segfaults.html">generator resume args segfaults</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="187845409"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generator%20resume%20args%20segfaults/near/187845409" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generator.20resume.20args.20segfaults.html#187845409">(Feb 10 2020 at 18:47)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="cp">#![feature(generators, generator_trait)]</span><span class="w"></span>

<span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">io</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">ops</span>::<span class="p">{</span><span class="n">Generator</span><span class="p">,</span><span class="w"> </span><span class="n">GeneratorState</span><span class="p">},</span><span class="w"></span>
<span class="p">};</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">my_scenario</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="n">Generator</span><span class="o">&lt;</span><span class="nb">String</span><span class="p">,</span><span class="w"> </span><span class="n">Yield</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="nb">&#39;static</span><span class="w"> </span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="n">Return</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">String</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="o">|</span><span class="n">_arg</span>: <span class="nb">String</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">my_name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kr">yield</span><span class="w"> </span><span class="s">&quot;What is your name?&quot;</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">my_mood</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kr">yield</span><span class="w"> </span><span class="s">&quot;How are you feeling?&quot;</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="n">format</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;{} is {}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">my_name</span><span class="p">.</span><span class="n">trim</span><span class="p">(),</span><span class="w"> </span><span class="n">my_mood</span><span class="p">.</span><span class="n">trim</span><span class="p">())</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">my_session</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Box</span>::<span class="n">pin</span><span class="p">(</span><span class="n">my_scenario</span><span class="p">());</span><span class="w"></span>

<span class="w">    </span><span class="k">loop</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">String</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>

<span class="w">        </span><span class="k">match</span><span class="w"> </span><span class="n">my_session</span><span class="p">.</span><span class="n">as_mut</span><span class="p">().</span><span class="n">resume</span><span class="p">(</span><span class="n">line</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">GeneratorState</span>::<span class="n">Yielded</span><span class="p">(</span><span class="n">prompt</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;{}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">prompt</span><span class="p">);</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">            </span><span class="n">GeneratorState</span>::<span class="n">Complete</span><span class="p">(</span><span class="n">v</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;{}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">v</span><span class="p">);</span><span class="w"></span>
<span class="w">                </span><span class="k">break</span><span class="p">;</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>

<span class="w">        </span><span class="n">line</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">String</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="n">io</span>::<span class="n">stdin</span><span class="p">().</span><span class="n">read_line</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">line</span><span class="p">).</span><span class="n">unwrap</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<div class="codehilite"><pre><span></span>./target/debug/example
What is your name?
Hello
How are you feeling?
world
zsh: segmentation fault  ./target/debug/so
</pre></div>



<a name="187845490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generator%20resume%20args%20segfaults/near/187845490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generator.20resume.20args.20segfaults.html#187845490">(Feb 10 2020 at 18:48)</a>:</h4>
<p>Since this is so new, I expect issues; where are we talking about generators nowadays?</p>



<a name="187850681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generator%20resume%20args%20segfaults/near/187850681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generator.20resume.20args.20segfaults.html#187850681">(Feb 10 2020 at 19:39)</a>:</h4>
<p>Nice catch!</p>



<a name="187851460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generator%20resume%20args%20segfaults/near/187851460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generator.20resume.20args.20segfaults.html#187851460">(Feb 10 2020 at 19:49)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink</span> is it? Should I go ahead and report it?</p>



<a name="187851517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generator%20resume%20args%20segfaults/near/187851517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generator.20resume.20args.20segfaults.html#187851517">(Feb 10 2020 at 19:50)</a>:</h4>
<p>Sure :)</p>



<a name="187851616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generator%20resume%20args%20segfaults/near/187851616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generator.20resume.20args.20segfaults.html#187851616">(Feb 10 2020 at 19:51)</a>:</h4>
<p>Can do!</p>



<a name="187852079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generator%20resume%20args%20segfaults/near/187852079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generator.20resume.20args.20segfaults.html#187852079">(Feb 10 2020 at 19:57)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/69039" target="_blank" title="https://github.com/rust-lang/rust/issues/69039">https://github.com/rust-lang/rust/issues/69039</a></p>



<a name="187945419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generator%20resume%20args%20segfaults/near/187945419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generator.20resume.20args.20segfaults.html#187945419">(Feb 11 2020 at 19:32)</a>:</h4>
<p>Is it bad if I have a little hope that I discovered a massive miscompilation issue?</p>



<a name="187949447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/generator%20resume%20args%20segfaults/near/187949447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/generator.20resume.20args.20segfaults.html#187949447">(Feb 11 2020 at 20:09)</a>:</h4>
<p>No, finding miscompilations is always good :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>